/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.hwr.nbaplan.shared.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author flo
 */
@Entity
@Table(name = "t_kurs", catalog = "nbaplan", schema = "")
@NamedQueries({
    @NamedQuery(name = "Kurs.findAll", query = "SELECT k FROM Kurs k"),
    @NamedQuery(name = "Kurs.findById", query = "SELECT k FROM Kurs k WHERE k.id = :id")})
public class Kurs implements Serializable {
 
    @Basic(optional = false)
    @Column(name = "semester", nullable = false)
    private short semester;
    @Column(name = "kursChar")
    private Character kursChar;
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID", nullable = false)
    private Integer id;
    @JoinColumn(name = "f_studiengang", referencedColumnName = "ID", nullable = false)
    @ManyToOne(optional = false)
    private Studiengang fStudiengang;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fKurs")
    private Collection<Modul> modulCollection;

    /**
     *
     */
    public Kurs() {
    }

    /**
     *
     * @param id
     */
    public Kurs(Integer id) {
        this.id = id;
    }

    /**
     *
     * @param studiengang
     * @param semster
     * @param kursChar
     */
    public Kurs(Studiengang studiengang, int semster, String kursChar) {
       this.fStudiengang=studiengang;
       this.semester=Short.parseShort(""+semster);
       if(kursChar.length()>0)
        this.kursChar=kursChar.charAt(0);

    }

    /**
     *
     * @return
     */
    public Integer getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(Integer id) {
        this.id = id;
    }

  
    /**
     *
     * @return
     */
    public Studiengang getFStudiengang() {
        return fStudiengang;
    }

    /**
     *
     * @param fStudiengang
     */
    public void setFStudiengang(Studiengang fStudiengang) {
        this.fStudiengang = fStudiengang;
    }

    /**
     *
     * @return
     */
    public Collection<Modul> getModulCollection() {
        return modulCollection;
    }

    /**
     *
     * @param modulCollection
     */
    public void setModulCollection(Collection<Modul> modulCollection) {
        this.modulCollection = modulCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Kurs)) {
            return false;
        }
        Kurs other = (Kurs) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.hwr.nbaplan.shared.model.Kurs[id=" + id + "]";
    }

    /**
     * 
     * @return
     */
    public short getSemester() {
        return semester;
    }

    /**
     *
     * @param semester
     */
    public void setSemester(short semester) {
        this.semester = semester;
    }

    /**
     *
     * @return
     */
    public Character getKursChar() {
        return kursChar;
    }
    /**
     *
     * @return
     */
    public String getMyKursChar() {
         if(kursChar==null)
             return "";
        return kursChar.toString();
    }

     /**
      *
      * @param kursChar
      */
     public void setKursChar(Character kursChar) {
        this.kursChar = kursChar;
    }



}
